package com.yu8home.mq.rabbit.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 广播交换机：将消息广播到所有绑定的队列
 */
@Configuration
public class FanoutConfig {
    String x = "yu8home.fanout.xxxx";
    String y = "yu8home.fanout.yyyy";

    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("yu8home.fanout");
    }

    @Bean
    public Queue fanoutQueueX() {
        return new Queue(x, true);// 持久化
    }

    @Bean
    public Queue fanoutQueueY() {
        return new Queue(y);
    }

    @Bean
    Binding bindingX(Queue fanoutQueueX, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueueX).to(fanoutExchange);
    }

    @Bean
    Binding bindingY(Queue fanoutQueueY, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueueY).to(fanoutExchange);
    }

}
